#pragma strict
//////////////////////////////////////////////////////
///射线的使用者.附加到玩枪支GameObject上.
//////////////////////////////////////////////////////
//射线构件
var laserPrefab:Transform;
//射线 发射点.
var muzzleLens:Transform;
//瞄准镜的名字.
var muzzleLensName:String  ="MuzzleLens";

private var laser:Laser;
private var tr:Transform;

function Start(){
	tr =  transform;
	Setup();
}

private function Setup(){
	if(!muzzleLens){
		muzzleLens = TransformHelper.RecursionFind(tr,muzzleLensName);
	}
	if(laserPrefab != null){
		var laserTransform:Transform = Instantiate(laserPrefab);
		laserTransform.parent = muzzleLens;
	    //设置目标	
	    laser = laserTransform.GetComponent(Laser);
	    laser.muzzleLens = muzzleLens;
	}
}

function Show(isShow:boolean){
	if(laser)
		laser.enabled = isShow;
}